{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">附件管理</div>
    <div class="layui-card-body">
        <blockquote class="layui-elem-quote quoteBox">
            <form class="layui-form searchForm" id="searchForm" method="get">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="filter_time_range" class="layui-input w200" id="laydate" placeholder="搜索时间范围">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="keyword" class="layui-input" placeholder="请输入附件名称">
                    </div>
                    <a class="layui-btn search_btn" data-type="reload" onclick="searchForm()">搜索</a>
                    <a class="layui-btn layui-btn-normal" onclick="resetForm()"><i class="layui-icon layui-icon-refresh-1"></i> 重置</a>
                </div>
            </form>
        </blockquote>
        <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm confirm layui-batch-all" data-href='{:url("delete")}'>批量删除</button>
    </div>
</script>
<script type="text/html" id="barTool">
    <a href='{:url("delete")}?ids={{ d.id }}' class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
</script>
{/block}
{block name="script"}
<script src="__STATIC__/libs/jquery-plugins/jquery.previewImage.js"></script>
<script>
    var options = {
        id: 'dataTable',
        formId: 'searchForm',
        toolbar: '#toolbarDemo',
        url: '{:url("index")}',
        page: true,
        sortOrder: '', //排序方式  asc: 升序、desc: 降序、null: 默认排序
        cols: [
            [
                { type: 'checkbox', fixed: 'left' },
                { field: 'id', width: 80, title: 'ID', sort: true },
                { field: 'aid', width: 80, title: '用户ID' },
                { field: 'name', width: 200, title: '名称' },
                { field: 'path', width: 450,align:"center",title: '物理路径',templet:'<div><a class="layui-btn layui-btn layui-btn-xs preview-img" href="{{d.path}}" target="_blank">{{d.path}}</a></div>'},
                { field: 'size',width: 100, title: '大小', sort: true },
                { field: 'ext',width: 100, title: '类型'},
                { field: 'mime',width: 120, title: 'Mime类型'},
                { field: 'driver',width: 100, title: '存储引擎'},
                { field: 'create_time', width: 160, title: '上传时间' },
                { fixed: 'right', width: 70, title: '操作', toolbar: '#barTool' }
            ]
        ],
        done: function(res, curr, count){
            $('.preview-img').previewImage();
        }, //表格数据渲染完的回调
    };
    // 搜索
    options.searchParams = function(){
        var formData = $.table._searchFormData();
        var data = {
            search_field: 'name',
            keyword: $('input[name="keyword"]').val(),
            filter_time: 'create_time',
            filter_time_range: $("#laydate").val(),
        };
        data = $.extend(formData, data);
        return data;
    };
    // 加载layui表格
    $.table.init(options);

    // laydate控件
    $.layui.laydate({
        elem: '#laydate',
        range: true,
    });
</script>
{/block}